package 曾世昌12_8.zuoye18;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;

public class test {
    public static void main(String[] args) throws Exception {
        List<String> strings = FileUtils.readLines( new File( "E:\\untitled5\\src\\rc\\mxdx3_zhoumozuoye\\zuoye18\\data.txt" ) );
        String str = "";
        for (String string : strings) {
            str = string;
        }
        Class<?> aClass = Class.forName( str );
        Method setId = aClass.getDeclaredMethod( "setId", String.class );
        setId.setAccessible( true );
        Method setName = aClass.getDeclaredMethod( "setName", String.class );
        setId.setAccessible( true );
        Method setAge = aClass.getDeclaredMethod( "setAge", int.class );
        setId.setAccessible( true );
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        List<String> string = FileUtils.readLines( new File( "E:\\untitled5\\src\\rc\\mxdx3_zhoumozuoye\\zuoye18\\data1.txt" ) );
        for (int i = 0; i < string.size(); i++) {
            String[] split = string.get( i ).split( "=" );
            for (int i1 = 0; i1 < split.length; i1++) {
                if (split[0].equals( "id" )) {
                    setId.invoke( o, split[1] );
                }
                if (split[0].equals( "name" )) {
                    setName.invoke( o, split[1] );
                }
                if (split[0].equals( "age" )) {
                    setAge.invoke( o, split[1] );
                }
            }
        }
    }
}
